import redis.clients.jedis.{Jedis, JedisPool, JedisPoolConfig}

/**
  * Created by danke on 2020/3/31.
  */
object JedisUtils {

  def createJedisPool(host:String,port:Int) = {
    //创建一个连接池的配置对象
    val config = new JedisPoolConfig()
    //最大空闲连接数，默认8个
    config.setMaxIdle(1000)
    //最大连接数，默认8个
    config.setMaxTotal(2000)
    config.setMinIdle(500)
    config.setMaxWaitMillis(10000)
    //获取一个连接池
    val pool:JedisPool = new JedisPool(config,host,port)
    pool
  }
  private def getJedis(host:String,port:Int):Jedis = {
    createJedisPool(host,port).getResource
  }
  def apply(host:String,port:Int):Jedis = {
    getJedis(host,port)
  }
}
